<template>
  <van-icon
    :color="value ? 'red' : '#777'"
    :name="value ? 'star' : 'star-o'"
    @click="setKeepFollow"
  />
</template>

<script>
import { addKeepFollow, deleteKeepFollow } from '@/api/user'

export default {
  props: {
    value: {
      type: Boolean,
      required: true
    },
    keysId: {
      type: [String, Number, Object],
      required: true
    }
  },
  data () {
    return {

    }
  },

  created () {

  },

  methods: {
    async setKeepFollow () {
      try {
        if (this.value) {
          await deleteKeepFollow(this.keysId)
          this.$toast('取消收藏成功')
        } else {
          await addKeepFollow(this.keysId)
          this.$toast('收藏文章成功')
        }
        this.$emit('input', !this.value)
      } catch (err) {
        this.$toast('操作失败，请重试')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
